from datetime import datetime, date
from pydantic import BaseModel, Field, ConfigDict
from typing import Optional, Literal
from pydantic.alias_generators import to_camel
from module_admin.annotation.pydantic_annotation import as_query
from pydantic_validation_decorator import Network, NotBlank, Size


class EmployeeModel(BaseModel):
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='员工ID')
    name: Optional[str] = Field(default=None, description='员工姓名')
    id_card: Optional[str] = Field(default=None, description='身份证信息')
    phone: Optional[str] = Field(default=None, description='联系电话')
    bank_card: Optional[str] = Field(default=None, description='银行卡号')
    hire_date: Optional[date] = Field(default=None, description='入职时间')
    resignation_date: Optional[date] = Field(default=None, description='离职时间')
    status: Optional[Literal['0', '1', '2']] = Field(default='0', description='员工状态（0在职 1离职 2停用）')
    del_flag: Optional[Literal['0', '2']] = Field(default='0', description='删除标志（0代表存在 2代表删除）')
    create_by: Optional[str] = Field(default=None, description='创建者')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')
    update_by: Optional[str] = Field(default=None, description='更新者')
    update_time: Optional[datetime] = Field(default=None, description='更新时间')

    @Size(field_name='phone', min_length=0, max_length=11, message='联系电话长度不能超过11个字符')
    def get_phone(self):
        return self.phone


@as_query
class EmployeeQueryModel(EmployeeModel):
    """
    员工管理不分页查询模型
    """
    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')
    begin_time: Optional[str] = Field(default=None, description='开始时间')
    end_time: Optional[str] = Field(default=None, description='结束时间')


class DeleteEmployeeModel(BaseModel):
    """
    删除员工模型
    """

    # 这句啥意思？
    model_config = ConfigDict(alias_generator=to_camel)

    employee_ids: str = Field(default=None, description='需要删除的员工id')
    update_by: Optional[str] = Field(default=None, description='更新者')
    update_time: Optional[str] = Field(default=None, description='更新时间')